package com.seafwg.store.controller;

import com.seafwg.store.entity.Address;
import com.seafwg.store.service.IAddressService;
import com.seafwg.store.utils.ResultJson;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


/**
 * @Author seafwg
 * @Date 2022/3/25 4:11 下午
 * @Version 1.0
 * @description 用户地址管理模块
 */
@RestController
@RequestMapping("/address")
public class AddressController extends BaseController{

    @Resource
    private IAddressService addressService;

    /**
     * 新增用户地址
     * @param address 地址信息
     * @param session session对象
     * @return
     */
    @RequestMapping("/add")
    public ResultJson<Void> addNewAddress(Address address, HttpSession session) {
        Integer uid = getUidFromSession(session);
        String username = getUsernameFormSession(session);

        addressService.addNewAddress(uid, username, address);
        return new ResultJson<>(OK);
    }

}
